CMake CMakeLists.txt:14错误(target 您所在的位置:网站首页 cmake add_library interface CMake CMakeLists.txt:14错误(target

CMake CMakeLists.txt:14错误(target

2023-03-27 12:31| 来源: 网络整理| 查看: 265

您的直觉是您的测试可执行程序需要以某种方式访问您的密码代码,以便测试它是正确的。但是,将可执行文件链接到另一个可执行文件是不可能的。

您需要将Cryptograph变成一个库,这样它就可以编译一次,并且您的可执行文件(cryptograph_samples和runCommonTests)可以链接到它。

库还应该而不是有一个main()。否则,它将在链接时与可执行文件的main()发生冲突。因此,假设Cryptograph/main.cpp包含一个main()函数,则应该排除它。

因此,将这一行替换为:

add_executable(Cryptograph main.cpp modulArithmetics.cpp ...)

通过以下方式:

add_library(Cryptograph STATIC modulArithmetics.cpp ...) # no main.cpp

使用STATIC库是一种方法。您还可以使用SHARED或OBJECT库。有关CMake库目标的更多信息,请参见下面的第一个参考链接。

如果需要执行Cryptograph/main.cpp,则可以将其转换为链接到Cryptograph的可执行文件,如Cryptograph/CMakeLists.txt中的

add_executable(CryptographApp main.cpp) target_link_libraries(CryptographApp Cryptograph)

资源

CMake target types and compositionGoogleTest guide on incorporating into an existing CMake project (~10行code).Integrating Google Test Into CMake Projects - by Matheus Gomes )说明了将依赖关系(如googletest)引入CMake项目的多种方法。


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有